package com.runvp.netty.server.handler;


import com.runvp.common.enums.NettyCmd;
import com.runvp.common.enums.NettyType;
import com.runvp.common.model.tcp.MessageResBody;
import com.runvp.common.util.enc.aes128gcm.HexStringToASCII;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class SendMsgHandle {

    /**
     * 构建发送消息
     * @param parseBody
     * @return byte[]
     */
    public static byte[] buildSendMsg(MessageResBody parseBody){
        return baseSendMsg(parseBody);
    }
    /**
     * 构建发送消息
     * @param parseBody
     * @return byte[]
     */
    public static byte[] baseSendMsg(MessageResBody parseBody){
        try{
            if(null == parseBody){
                log.error("3-baseSendMsg-parseBody为空，执行结束");
                return null;
            }
            String type = parseBody.getType();
            String cmd = parseBody.getCmd();
            String resCmd = parseBody.buildCmd();
            log.info("3-本次【{}】消息type:{},cmd:{},cmdDesc:{},resCmd:{}",NettyType.getDesc(parseBody.getType()),type,cmd, NettyCmd.getDesc(type,cmd),resCmd);
            byte [] all = HexStringToASCII.hexToAsciiByte(resCmd);
//            byte [] all = HexStringToASCII.hexToAsciiByte("3A3A040100000000003E0100616BE31427FC79114ED9A77DA48498933CFBB0CA4CDE386537DD4FFE13A99D69E149A2D50B9E132FA80E80D909A0AC259D447DC0CAA39F867A092660FB182F7C6ACDE797B15A8D87C7AF9111D9A6469D7B7F1BAE21247A52B4FD08F54745CB3D63AAFC435D535D0FBEE45A10022562462EB8");

            return all;
        }catch (Exception e){
            log.error("3-发送消息数据组装异常 : {}",e.getMessage());
            return null;
        }
    }
}
